# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=casa-client
pkgname=haskell-casa-client
pkgver=0.0.1
pkgrel=577
pkgdesc="Content Addressable Storage Archive client"
url="https://github.com/fpco/casa"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-attoparsec' 'haskell-base16-bytestring'
         'haskell-casa-types' 'haskell-conduit' 'haskell-conduit-extra' 'haskell-cryptonite'
         'haskell-http-conduit' 'haskell-http-types' 'haskell-memory'
         'haskell-network-uri' 'haskell-resourcet' 'haskell-th-lift' 'haskell-unliftio-core'
         'haskell-unordered-containers')
makedepends=('ghc')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('2df03a0b1c2e01f2d24728e96fe446a25b630f5495c4e9995bcbde1ee9da530df1c6b40dde954cfaf6de2af6036fa6cfda7d9957b22106316557cc57d64114fa')

prepare() {
    cd $_hkgname-$pkgver
    echo -e "import Distribution.Simple\nmain = defaultMain" > Setup.hs
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
